package com.demo2.todo.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import com.demo2.todo.model.entity.Report;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 举报信息的数据访问层接口
 * @author evi
 */
public interface ReportRepository extends JpaRepository<Report, Long> {

    /**
     * 按创建时间降序查询所有举报
     */
    List<Report> findAllByOrderByCreatedAtDesc();

    /**
     * 根据状态查询举报
     */
    List<Report> findByStatusOrderByCreatedAtDesc(Report.ReportStatus status);

    /**
     * 检查用户是否已举报过某个todo
     */
    boolean existsByTodoIdAndReporterId(Long todoId, Long reporterId);
    /**
     * 根据待办事项ID删除举报
     */
    @Modifying
    @Query("DELETE FROM Report r WHERE r.todoId = :todoId")
    void deleteByTodoId(@Param("todoId") Long todoId);
}

